home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / WOLEAUTO.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  17.2 KB  |  499 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. #ifndef _WOLEAUTO_HPP_INCLUDED
  12. #define _WOLEAUTO_HPP_INCLUDED
  13.  
  14. #ifndef _WNO_PRAGMA_PUSH
  15. #pragma pack(push,8);
  16. #pragma enum int;
  17. #endif
  18.  
  19. #include <stdarg.h>
  20. #ifndef _WOLETYPE_HPP_INCLUDED
  21. #   include "woletype.hpp"
  22. #endif
  23. #ifndef _WSTRING_HPP_INCLUDED
  24. #   include "wstring.hpp"
  25. #endif
  26. #ifndef _WOLEBSTR_HPP_INCLUDED
  27. #   include "wolebstr.hpp"
  28. #endif
  29. #ifndef _WBUFFER_HPP_INCLUDED
  30. #   include "wbuffer.hpp"
  31. #endif
  32. #ifndef _WARRAY_HPP_INCLUDED
  33. #  include "warray.hpp"
  34. #endif
  35.  
  36. enum WAmbientID {
  37.     WAmbient_BACKCOLOR         = (-701)
  38. ,   WAmbient_DISPLAYNAME       = (-702)
  39. ,   WAmbient_FONT              = (-703)
  40. ,   WAmbient_FORECOLOR         = (-704)
  41. ,   WAmbient_LOCALEID          = (-705)
  42. ,   WAmbient_MESSAGEREFLECT    = (-706)
  43. ,   WAmbient_SCALEUNITS        = (-707)
  44. ,   WAmbient_TEXTALIGN         = (-708)
  45. ,   WAmbient_USERMODE          = (-709)
  46. ,   WAmbient_UIDEAD            = (-710)
  47. ,   WAmbient_SHOWGRABHANDLES   = (-711)
  48. ,   WAmbient_SHOWHATCHING      = (-712)
  49. ,   WAmbient_DISPLAYASDEFAULT  = (-713)
  50. ,   WAmbient_SUPPORTSMNEMONICS = (-714)
  51. ,   WAmbient_AUTOCLIP          = (-715)
  52. };
  53.  
  54. enum WDispatchFlag {
  55.     WDispatchFlag_Method                = 0x1
  56. ,   WDispatchFlag_PropertyGet           = 0x2
  57. ,   WDispatchFlag_PropertyPut           = 0x4
  58. ,   WDispatchFlag_PropertyPutRef        = 0x8
  59. };
  60.  
  61. enum WInvokeError {
  62.     WInvokeError_None
  63. ,   WInvokeError_HelperNotInitialized
  64. ,   WInvokeError_NoErrorInfo
  65. ,   WInvokeError_CallNotMade
  66. ,   WInvokeError_OutOfMemory
  67. ,   WInvokeError_TooManyParams
  68. ,   WInvokeError_BadNamedParam
  69. ,   WInvokeError_BadParamCount
  70. ,   WInvokeError_BadParamArray
  71. ,   WInvokeError_BadVarType
  72. ,   WInvokeError_Exception
  73. ,   WInvokeError_MemberNotFound
  74. ,   WInvokeError_Overflow
  75. ,   WInvokeError_ParamNotFound
  76. ,   WInvokeError_TypeMismatch
  77. ,   WInvokeError_Error
  78. };
  79.  
  80. /*************************************************************************
  81.  *
  82.  * WExceptionInfo -- Exception Information
  83.  *
  84.  *
  85.  *   Events:
  86.  *
  87.  *
  88.  *************************************************************************/
  89.  
  90. class WCMCLASS WExceptionInfo {
  91.  
  92.     public:
  93.  
  94.     /**********************************************************
  95.      * Constructors and Destructors
  96.      *********************************************************/
  97.         WExceptionInfo();
  98.         WExceptionInfo( const WExceptionInfo & excep );
  99.         WExceptionInfo( WPIErrorInfo pErrorInfo );
  100.         ~WExceptionInfo();
  101.  
  102.     public:
  103.  
  104.     /**************************************************************
  105.      * Properties
  106.      **************************************************************/
  107.  
  108.         // WCode
  109.         WBool SetWCode( WUShort wcode );
  110.         WUShort GetWCode() const;
  111.  
  112.         // Scode
  113.         WBool SetSCode( WScode scode );
  114.         WScode GetSCode() const;
  115.  
  116.         // Description
  117.         WBool SetDescription( const WString & description );
  118.         WString GetDescription() const;
  119.  
  120.         // Help File
  121.         WBool SetHelpFile( const WString & helpFile );
  122.         WString GetHelpFile() const;
  123.  
  124.         // Source
  125.         WBool SetSource( const WString & source );
  126.         WString GetSource() const;
  127.  
  128.         // Help Context
  129.         WBool SetHelpContext( WULong helpContext );
  130.         WULong GetHelpContext() const;
  131.  
  132.         // GUID
  133.         WBool SetGUID( const WGUID & guid );
  134.         WGUID GetGUID() const;
  135.  
  136.         // ExceptionInfo
  137.         WBool SetExceptionInfo( void );
  138.         WBool GetExceptionInfo( WPIDispatch disp );
  139.  
  140.     /**************************************************************
  141.      * Methods
  142.      **************************************************************/
  143.  
  144.         WBool Create( WPIErrorInfo pErrorInfo );
  145.  
  146.         void Display( void );
  147.  
  148.         static WBool ClearExceptionInfo( void );
  149.  
  150.     /**********************************************************
  151.      * Operators
  152.      *********************************************************/
  153.     
  154.         WExceptionInfo & operator=( const WExceptionInfo & excep );
  155.  
  156.     private:
  157.  
  158.     /**********************************************************
  159.      * Data Members
  160.      *********************************************************/
  161.     
  162.         WUShort         _wCode;
  163.         WScode          _scode;
  164.         WString         _source;
  165.         WString         _description;
  166.         WString         _helpFile;
  167.         WULong          _helpContext;
  168.         WGUID           _guid;
  169. };
  170.  
  171.  
  172. enum WVarEnum {
  173.     WVT_EMPTY           = 0,
  174.     WVT_NULL            = 1,
  175.     WVT_I2              = 2,
  176.     WVT_I4              = 3,
  177.     WVT_R4              = 4,
  178.     WVT_R8              = 5,
  179.     WVT_CY              = 6,
  180.     WVT_DATE            = 7,
  181.     WVT_BSTR            = 8,
  182.     WVT_DISPATCH        = 9,
  183.     WVT_ERROR           = 10,
  184.     WVT_BOOL            = 11,
  185.     WVT_VARIANT         = 12,
  186.     WVT_UNKNOWN         = 13,
  187.     WVT_I1              = 16,
  188.     WVT_UI1             = 17,
  189.     WVT_UI2             = 18,
  190.     WVT_UI4             = 19,
  191.     WVT_I8              = 20,
  192.     WVT_UI8             = 21,
  193.     WVT_INT             = 22,
  194.     WVT_UINT            = 23,
  195.     WVT_VOID            = 24,
  196.     WVT_HRESULT         = 25,
  197.     WVT_PTR             = 26,
  198.     WVT_SAFEARRAY       = 27,
  199.     WVT_CARRAY          = 28,
  200.     WVT_USERDEFINED     = 29,
  201.     WVT_LPSTR           = 30,
  202.     WVT_LPWSTR          = 31,
  203.     WVT_FILETIME        = 64,
  204.     WVT_BLOB            = 65,
  205.     WVT_STREAM          = 66,
  206.     WVT_STORAGE         = 67,
  207.     WVT_STREAMED_OBJECT = 68,
  208.     WVT_STORED_OBJECT   = 69,
  209.     WVT_BLOB_OBJECT     = 70,
  210.     WVT_CF              = 71,
  211.     WVT_CLSID           = 72,
  212.  
  213.     // extensions for ole controls
  214.     WVT_COLOR           = WVT_I4,
  215.     WVT_XPOS_PIXELS     = WVT_I4,
  216.     WVT_YPOS_PIXELS     = WVT_I4,
  217.     WVT_XSIZE_PIXELS    = WVT_I4,
  218.     WVT_YSIZE_PIXELS    = WVT_I4,
  219.     WVT_XPOS_HIMETRIC   = WVT_I4,
  220.     WVT_YPOS_HIMETRIC   = WVT_I4,
  221.     WVT_XSIZE_HIMETRIC  = WVT_I4,
  222.     WVT_YSIZE_HIMETRIC  = WVT_I4,
  223.     WVT_TRISTATE        = WVT_I2,
  224.     WVT_OPTEXCLUSIVE    = WVT_BOOL,
  225.     WVT_FONT            = WVT_DISPATCH,
  226.     WVT_PICTURE         = WVT_DISPATCH,
  227.  
  228.     // 4 BYTE windows handle
  229.     WVT_HANDLE          = WVT_I4
  230. };
  231.  
  232. #define WVT_VECTOR      (0x1000)
  233. #define WVT_ARRAY       (0x2000)
  234. #define WVT_BYREF       (0x4000)
  235. #define WVT_RESERVED    (0x8000)
  236.  
  237. #define WDISP_E_PARAMNOTFOUND   0x80020004L
  238. #define WDISP_E_EXCEPTION       0x80020009L
  239. #define W_INV_ALL_PARAMS        0xffffffff
  240.  
  241. typedef unsigned short WVarType;
  242.  
  243. // forward type declaration
  244. struct _WVARIANT;
  245.  
  246. typedef struct _WVARIANT {
  247.  
  248.     /**********************************************************
  249.      * Data Members
  250.      *********************************************************/
  251.     
  252.     WVarType            vt;
  253.     unsigned short      wReserved1;
  254.     unsigned short      wReserved2;
  255.     unsigned short      wReserved3;
  256.     union
  257.     {
  258.         unsigned char   bVal;           /* WVT_UI1                      */
  259.         short           iVal;           /* WVT_I2                       */
  260.         long            lVal;           /* WVT_I4                       */
  261.         float           fltVal;         /* WVT_R4                       */
  262.         double          dblVal;         /* WVT_R8                       */
  263.         WVARIANT_BOOL   boolVal;        /* WVT_BOOL                     */
  264.         WScode          scode;          /* WVT_ERROR                    */
  265.         WCurrency       cyVal;          /* WVT_CY                       */
  266.         WDate           date;           /* WVT_DATE                     */
  267.         WBStr           bstrVal;        /* WVT_BSTR                     */
  268.         WPIUnknown      punkVal;        /* WVT_UNKNOWN                  */
  269.         WPIDispatch     pdispVal;       /* WVT_DISPATCH                 */
  270.         WSafeArray      *parray;        /* WVT_ARRAY|*                  */
  271.         unsigned char   *pbVal;         /* WVT_BYREF|WVT_UI1            */
  272.         short           *piVal;         /* WVT_BYREF|WVT_I2             */
  273.         long            *plVal;         /* WVT_BYREF|WVT_I4             */
  274.         float           *pfltVal;       /* WVT_BYREF|WVT_R4             */
  275.         double          *pdblVal;       /* WVT_BYREF|WVT_R8             */
  276.         WVARIANT_BOOL   *pboolVal;      /* WVT_BYREF|WVT_BOOL           */
  277.         WScode          *pscode;        /* WVT_BYREF|WVT_ERROR          */
  278.         WCurrency       *pcyVal;        /* WVT_BYREF|WVT_CY             */
  279.         WDate           *pdate;         /* WVT_BYREF|WVT_DATE           */
  280.         WBStr           *pbstrVal;      /* WVT_BYREF|WVT_BSTR           */
  281.         WPIUnknown      *ppunkVal;      /* WVT_BYREF|WVT_UNKNOWN        */
  282.         WPIDispatch     *ppdispVal;     /* WVT_BYREF|WVT_DISPATCH       */
  283.         WSafeArray      **pparray;      /* WVT_BYREF|WVT_ARRAY|*        */
  284.         _WVARIANT       *pvarVal;       /* WVT_BYREF|WVT_VARIANT        */
  285.         void            *byref;         /* Generic ByRef                */
  286.  
  287.         // WClass extras
  288.         unsigned short  uiVal;          /* WVT_UI2                      */
  289.         unsigned long   ulVal;          /* WVT_UI4                      */
  290.         char            cVal;           /* WVT_I1                       */
  291.         unsigned int    uintVal;        /* WVT_UINT                     */
  292.         int             intVal;         /* WVT_INT                      */
  293.         char            *pcVal;         /* WVT_BYREF|WVT_I1             */
  294.         unsigned short  *puiVal;        /* WVT_BYREF|WVT_UI2            */
  295.         unsigned long   *pulVal;        /* WVT_BYREF|WVT_UI4            */
  296.         unsigned int    *puintVal;      /* WVT_BYREF|WVT_UINT           */
  297.         int             *pintVal;       /* WVT_BYREF|WVT_INT            */
  298.         WBString        *pwbstringVal;
  299.     };
  300. } _WVARIANT;
  301.  
  302.  
  303. typedef _WVARIANT WVARIANT;
  304.  
  305. class WVariant;
  306.  
  307. extern template WArrayReference<WVariant>;
  308. extern template WArray<WVariant>;
  309.  
  310. typedef WArray<WVariant> WVariantArray;
  311.  
  312. /*************************************************************************
  313.  *
  314.  * WVariant
  315.  *
  316.  *
  317.  *   Events:
  318.  *
  319.  *
  320.  *************************************************************************/
  321.  
  322. // The contents of this class are not managed in any way.
  323. // This means that no attempt is made to call Release through
  324. // interface pointers, etc. The only exception to this rule are
  325. // strings.
  326. class WCMCLASS WVariant : public _WVARIANT {
  327.  
  328.     public:
  329.  
  330.         /**********************************************************
  331.          * Constructors and Destructors
  332.          *********************************************************/
  333.  
  334.         WVariant( void );
  335.         WVariant( unsigned char b );
  336.         WVariant( short s );
  337.         WVariant( long l );
  338.         WVariant( float flt );
  339.         WVariant( double dbl );
  340.         WVariant( WCurrency cy );
  341.         WVariant( WBStr bstr );
  342.         WVariant( WPIUnknown punk );
  343.         WVariant( WPIDispatch pdisp );
  344.         WVariant( WSafeArray *p );
  345.         WVariant( unsigned char *pb );
  346.         WVariant( short *pi );
  347.         WVariant( long *pl );
  348.         WVariant( float *pflt );
  349.         WVariant( double *pdbl );
  350.         WVariant( WCurrency *pcy );
  351.         WVariant( WBStr *pbstr );
  352.         WVariant( WPIUnknown *ppunk );
  353.         WVariant( WPIDispatch *ppdisp );
  354.         WVariant( WSafeArray **ppa );
  355.         WVariant( WVariant *pvar );
  356.         WVariant( unsigned short ui );
  357.         WVariant( unsigned long ul );
  358.         WVariant( char c );
  359.         WVariant( unsigned int ui );
  360.         WVariant( int i );
  361.         WVariant( unsigned short *pui );
  362.         WVariant( unsigned long *pul );
  363.         WVariant( unsigned int *puint );
  364.         WVariant( int *pint );
  365.  
  366.         // Ambiguous with short:
  367.         // WVariant( WVARIANT_BOOL b )  { vt = WVT_BOOL; boolVal = b; freeMember = isWBString = FALSE; SetReserved(); };
  368.         // Ambiguous with long:
  369.         // WVariant( WScode sc )        { vt = WVT_ERROR; scode = sc; freeMember = isWBString = FALSE; SetReserved(); };
  370.         // Ambiguous with double:
  371.         // WVariant( WDate dt )         { vt = WVT_DATE; date = dt; freeMember = isWBString = FALSE; SetReserved(); };
  372.         // Ambiguous with short *:
  373.         // WVariant( WVARIANT_BOOL *pb ){ vt = WVT_BYREF|WVT_BOOL; pboolVal = pb; freeMember = isWBString = FALSE; SetReserved(); };
  374.         // Ambiguous with long *:
  375.         // WVariant( WScode *psc )      { vt = WVT_BYREF|WVT_ERROR; pscode = psc; freeMember = isWBString = FALSE; SetReserved(); };
  376.         // Ambiguous with double *:
  377.         // WVariant( WDate *pdt )       { vt = WVT_BYREF|WVT_DATE; pdate = pdt; freeMember = isWBString = FALSE; SetReserved(); }
  378.  
  379.         // Amibiguous the the string constructors.
  380.         // WVariant( char *pc )         { vt = WVT_BYREF|WVT_I1; pcVal = pc; freeMember = isWBString = FALSE; SetReserved(); };
  381.  
  382.         WVariant( const WChar * const str );
  383.  
  384.         // The following constuctor sets freeMember to TRUE and
  385.         // cause BSTR's to be allocated NOT pointers to WStrings.
  386.         WVariant( const WString & str );
  387.         WVariant( const WBString & wbstr );
  388.  
  389.         // Copy constructor. This member will cause BSTR's or WString pointers
  390.         // to be allocated instead of copied if freeMember is TRUE
  391.         WVariant( const WVariant & var );
  392.  
  393.         WVariant( const _WVARIANT & var );
  394.  
  395.         // WBuffer constructor. This member will cause a BSTR to be allocated
  396.         WVariant( const WBuffer & buffer );
  397.  
  398.         // WVariantArray constructor. This member will cause a
  399.         // SAFEARRAY of VARIANTS to be allocated
  400.         WVariant( WVariantArray & variantArray );
  401.  
  402.         ~WVariant();
  403.  
  404.         /**************************************************************
  405.          * Methods
  406.          **************************************************************/
  407.  
  408.         void Init( void );
  409.         WBool Clear( void );
  410.         WBool ChangeType( const WVarType vtNew );
  411.         WBool ChangeType( WVariant & dest, const WVarType vtNew );
  412.     
  413.         // NOTE: If vt is WVT_BSTR then the argument is a WString *
  414.         WBool Assign( void * val, WVarType type );
  415.     
  416.         // NOTE: If vtSet is WVT_BSTR then the argument is expected to
  417.         // be a WChar *
  418.         WBool Set( const WVarType vtSet, va_list arg );
  419.     
  420.         WBool BStrToWBString( void );
  421.         WBool WBStringToBStr( void );
  422.         WBool IsWBString();
  423.  
  424.         /**************************************************************
  425.          * Internal Methods
  426.          **************************************************************/
  427.  
  428.         void SetReserved( void );
  429.  
  430.         /**************************************************************
  431.          * Operators
  432.          **************************************************************/
  433.  
  434.         WVariant & operator=( const WVariant & var );
  435.  
  436.         // cast operators
  437.  
  438.         operator unsigned char() const;
  439.         operator short() const;
  440.         operator long() const;
  441.         WCMRETURNSFLOAT operator float() const;
  442.         WCMRETURNSFLOAT operator double() const;
  443.         //operator WVARIANT_BOOL() const;
  444.         //operator WScode() const;
  445.         operator WCurrency() const;
  446.         //operator WDate() const;
  447.         //operator WBStr();
  448.         operator WString();
  449.         operator WBString();
  450.         operator WBuffer();
  451.         operator WPIUnknown() const;
  452.         operator WPIDispatch() const;
  453.         operator WSafeArray *() const;
  454.  
  455.         operator unsigned char *() const;
  456.         operator short *() const;
  457.         operator long *() const;
  458.         operator float *() const;
  459.         operator double *() const;
  460.         //operator WVARIANT_BOOL *() const;
  461.         //operator WScode *() const;
  462.         operator WCurrency *() const;
  463.         //operator WDate *() const;
  464.         operator WBStr *() const;
  465.         operator WPIUnknown *() const;
  466.         operator WPIDispatch *() const;
  467.         operator WSafeArray **() const;
  468.         operator _WVARIANT *() const;
  469.         operator void *() const;
  470.  
  471.         operator unsigned short() const;
  472.         operator unsigned long() const;
  473.         operator char() const;
  474.         operator unsigned int() const;
  475.         operator int() const;
  476.         //operator char *() const;
  477.         operator unsigned short *() const;
  478.         operator unsigned long *() const;
  479.         operator unsigned int *() const;
  480.         operator int *() const;
  481.         operator WBString *();
  482.  
  483.     /**********************************************************
  484.      * Data Members
  485.      *********************************************************/
  486.  
  487.     private:
  488.         WBool freeMember;
  489.         WBool isWBString;
  490.     
  491. };
  492.  
  493. #ifndef _WNO_PRAGMA_PUSH
  494. #pragma enum pop;
  495. #pragma pack(pop);
  496. #endif
  497.  
  498. #endif // _WOLEAUTO_HPP_INCLUDED
  499.